package com.liangzong.betspider.entity;

import io.swagger.annotations.ApiModel;
import lombok.Data;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.time.LocalDateTime;
import java.util.List;

@Data
@ApiModel
@Table(name = "t_team")
public class TeamInfo {
    @Id
    @Column(name = "id")
    private String id;
    @Column(name = "url")
    private String url;
    @Column(name = "home_team_name")
    private String homeTeamName;
    @Column(name = "away_team_name")
    private String awayTeamName;
    @Column(name = "time")
    private String time;
    @Column(name = "add_time")
    private LocalDateTime addTime;
    @Column(name = "update_time")
    private LocalDateTime updateTime;
    @Column(name = "refresh_times")
    private Integer refresh_times;
    @Column(name = "state")
    private Integer state;
    @Column(name = "over_time")
    private LocalDateTime overTime;

    @Transient
    private List<TeamPoint> homeTeamPointList;
    @Transient
    private List<TeamPoint> awayTeamPointList;
    @Transient
    private TeamScore homeTeamScore;
    @Transient
    private TeamScore awayTeamScore;


    public boolean isReady() {
        return !isAnyBlank(id, url, time);
    }

    private boolean isAnyBlank(String... str) {
        if (str == null) {
            return true;
        }
        for (String s : str) {
            if (s == null || "".equals(str)) {
                return true;
            }
        }
        return false;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder("");
        sb.append("\n\r");
        sb.append("id=").append(id).append("\n\r");
        sb.append("url=").append(url).append("\n\r");
        sb.append("time=").append(time).append("\n\r");
        sb.append("homeTeamName=").append(homeTeamName).append("\tvs\t").append("awayTeamName=").append(awayTeamName).append("\n\r");
        sb.append("homeTeamScore").append("\n\r");
        sb.append(homeTeamScore).append("\n\r");
        sb.append("awayTeamScore").append("\n\r");
        sb.append(awayTeamScore).append("\n\r");
        sb.append("盘口").append("\n\r");
        for (int i = 0; homeTeamPointList != null && i < homeTeamPointList.size(); i++) {
            TeamPoint homeTeamPoint = homeTeamPointList.get(i);
            TeamPoint awayTeamPoint = awayTeamPointList.get(i);
            sb.append(homeTeamPoint.getHd());
            if (homeTeamPoint.getHd() != null && homeTeamPoint.getHd().length() < 6) {
                sb.append("\t");
            }
            sb.append("\t").append(homeTeamPoint.getOd()).append("\t");
            sb.append("--");
            sb.append(awayTeamPoint.getHd());
            if (awayTeamPoint.getHd() != null && awayTeamPoint.getHd().length() < 6) {
                sb.append("\t");
            }
            sb.append("\t").append(awayTeamPoint.getOd()).append("\n\r");
        }
        return sb.toString();
    }
}
